# coding=gbk
'''
Created on 2010-12-17

@author: yaron hu
'''

import wx
import os
import sys
import codecs
class SizerFrame(wx.Frame):
  def __init__(self, panel, id):
    wx.Frame.__init__(self, panel, id, "Resize Window", size=(400, 300))
    menuBar = wx.MenuBar()
    menuFile = wx.Menu()
    menuFileOpen = menuFile.Append(-1, "Open", "Open Files")
    self.Bind(wx.EVT_MENU, self.OnOpenFile, menuFileOpen)
    menuFileQuit = menuFile.Append(-1, "Quit", "Quit Application")
    self.Bind(wx.EVT_MENU, self.OnQuit, menuFileQuit)
    menuBar.Append(menuFile, "&File")
    self.SetMenuBar(menuBar)
    self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
    
    self.richText = wx.TextCtrl(self, -1, style=wx.TE_MULTILINE | wx.TE_RICH2)
    self.richText.SetBackgroundColour("#CCCCCC")
    self.Centre()
    
    
  def OnQuit(self, event):
    self.Close()
    
  def OnCloseWindow(self, evet):
    self.Destroy()
    
  def OnOpenFile(self, evet):
    dlg = wx.FileDialog(self, message="Choose A File", defaultDir="D:\\", 
                  defaultFile="", wildcard="*.*", style=0)
    if dlg.ShowModal()==wx.ID_OK:
      fileHandle = open(dlg.GetPath(),'r')
      type = sys.getfilesystemencoding()
      data = fileHandle.read()
      self.richText.SetValue(data)
      dlg.Destroy()
  
if __name__ == '__main__':
  app = wx.PySimpleApp()
  sf = SizerFrame(None, -1)
  sf.Show()
  app.MainLoop()
